import { request } from './request.js'
request.defaultData.baseUrl = 'http://cyjs.pzhkj.cn/'

export function uploadFile(data) {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/common/upload',
        method: 'POST',
        header: {
          'Content-Type': 'multipart/form-data',
        },
        data,
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function toggleFav({ caipiao_id, chu, zuhe }) {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/customers/favToggle',
        method: 'POST',
        data: {
          caipiao_id,
          chu,
          zuhe: zuhe.replace(/,/g, '_'),
        },
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function getCaipiaoCategoryList() {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/index/getCpList',
        method: 'POST',
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}
